<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table cellspacing="0" border="0" width="995">
	<tr>
		<td width="995" class="title_manager_product">Quản lý tin tức</td>
	</tr>
	<tr>
		<td>
			<table border="0" cellpadding="0" cellspacing="0" width="995">
				<tr>
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><img src="images/CreateNews.gif" width="48" height="47" border="0" /></td>
							</tr>
							<tr>
								<td align="center" class="title_new_add"><a href="index.php?admin=newAdmin&do=formaddnews">Thêm tin tức</a></td>
							</tr>
						</table>
						
					</td>
					
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><img src="images/CreateCategory.gif" width="51" height="48" border="0" /></td>
							</tr>
							<tr>
								<td align="center" class="title_new_add"><a href="index.php?admin=newAdmin&do=formaddnewtype">Thêm kiểu tin tức</a></td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>	
	</tr>
</table>
<table cellspacing="0" border="0" width="995">
	<tr>
		<td width="200" valign="top">					
			<?php
				include("menuleftnew.php");
			?>
		</td>	
		<td width="790" valign="top">
			<table cellspacing="0" border="0" width="790">
				<tr>
				
				</tr>
			</table>
			
			<table cellspacing="0" cellpadding="0" border="0" width="790">
				<tr>
					<td>
						<?php
							$id=$_GET['id'];
						?>
						<form action="index.php?admin=newAdmin&do=formeditnews&id=<?php echo $id?>" method="post" enctype="multipart/form-data">
							<table cellspacing="0" border="0" width="790">
									<tr>
										<td width="790" class="title_manager_cate">Sửa tin tức</td>
									</tr>
								</table>
							<table class="reference" cellspacing="0" border="1" width="790">
								<tr>
									<td colspan="2" align="center">
										<?php
											$id=$_GET['id'];
											$newName=$_POST['newName'];
											$newDetail=$_POST['newDetail'];
											$newID=$_POST['newID'];
											$state=$_POST['state'];
											$newContent=$_POST['newContent'];
											
											$target="../user/upload/news/";
											$image = $_FILES['newImage']['name'];
											$link = $target.$image;
											move_uploaded_file($_FILES['newImage']['tmp_name'],$link);
												if(isset($_POST['submit'])){
													if($image==''){
													$query="UPDATE newdetails SET newName='$newName',newDetail='$newDetail',newContent='$newContent',newID='$newID',state='$state' WHERE id=$id";	
												}else{
													$query="UPDATE newdetails SET newName='$newName',newDetail='$newDetail',newImage='$link',newContent='$newContent',newID='$newID',state='$state' WHERE id=$id";	
												}
												if($newName==''){
													echo "<font color=\"red\">Bạn phải nhập vào tiêu đề tin.</font>";
												}else{
													mysql_query($query);
													echo "Sửa tin tức thành công.";
													echo "<script>window.location='index.php?admin=newAdmin&do=listnew'</script>";	
												}		
											}
										?>
									</td>
								</tr>	
							<?php
								$query="SELECT * FROM newdetails where id=$id";
								$result=mysql_query($query);
								while($rows=mysql_fetch_array($result)){?>
				                    <tr>
				                        <td align="right"><b>Tiêu đề:</b></td>
				                        <td><input type="text" name="newName" value="<?php echo $rows['newName']?>" size="40" maxlength="250" /></td>
				                    </tr>
				                     <tr>
				                        <td align="right"><b>Mô tả tin:</b></td>
				                        <td>
				                            <input type="text" name="newDetail" value="<?php echo $rows['newDetail']?>" size="50" />
				                        </td>
				                    </tr>
				                    <tr>
				                        <td align="right"><b>Loại tin:</b></td>
				                        <td>
				                            <select name="newID">
				                                <?php					
				                                $query2 = "select * from news";
				                                $result2=mysql_query($query2);
				                                while($row2=mysql_fetch_array($result2)){?>
				                                    <option value="<?php echo $row2['id']?>"
				                                    	<?php 
															if($rows['newID']==$row2['id']){
																echo "selected";
															}
														?>
				                                    ><?php echo $row2['titleNew'];?></option>	
				                                <?php
				                                }
				                                ?>
				                             </select>   
				                        </td>
				                    </tr>
				                    <tr>
				                        <td align="right"><b>Trạng thái:</b></td>
				                        <td>
				                            <select name="state">
				                                <option value="on" <?php 
													if($rows['state']=='on'){
														echo "selected";
													}
												?>>Hiện tin</option>
				                                <option value="off" <?php
				                                	if($rows['state']=='off'){
														echo "selected";
													}
												?>>Ẩn tin</option>
				                            </select>
				                        </td>
				                    </tr>
				                    <tr>
						                <td align="right"><b>Tin ảnh:</b></td>
						                <td>
						                    <input type="file" name="newImage" />
						                </td>
						            </tr>
				                    <tr>
				                        <td align="right"><b>Nội dung:</b></td>
				                        <td>
				                            <textarea name="newContent" rows="20"><?php echo $rows['newContent']?></textarea>
				                        </td>
				                    </tr>                                  
						            
								<?php
						        }
								?>
						        <tr>
						            <td></td>
						            <td>
						                <input type="submit" name="submit" value="Sửa tin" />
						                <input type="reset" name="reset" value="Nhập lại" />
						                <input type="button" name="Cancel" value="Cancel" onclick="window.location = 'index.php?admin=newAdmin&do=listnew' " />    
						            </td>
						        </tr>
						    </table>
						</form>	
					</td>
				</tr>				
			</table>
		</td>
	</tr>	
</table>
</body>
</html>